<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<c:set var="ApprovePage" value="${not empty param.businessKey}" />
<!DOCTYPE html>
<html>
<head>
<title>任务办理</title>
<script src="${ctx}/static/selectWin/employeeSelector.js?version=${applicationScope.jsVersion }" type="text/javascript"></script>
<script type="text/javascript">
	document.onmousedown = function(e) {
	};
	document.onmousemove = function(e) {
	};
	document.onmouseup = function(e) {
	};
	document.ondblclick = function(e) {
	};
	$(function() {
		<c:if test="${not empty assigneeUrl}">
		if ("${userFlag}" == "0") {
			$(".info").css("color", "red").text("*未找到该角色下的人员!");
		} else if ("${userFlag}" == "2") {
			$(".info").css("color", "red");
			$(".info").text("找到了2个及以上的人员");
		} else {
			if("${userFlag}"){
				$("#nextAssignee").combobox("select", "${userFlag}");
			}else{
				/* setTimeout(function(){
					var data = $('#nextAssignee').combobox('getData');
			        if (data.length > 0) {
			            $("#nextAssignee").combobox('select', data[0].value);
			        }
				},3000); */
			}
		}
		//$("#nextAssignee").combobox({required: true}); // 默认必填
		
		</c:if>


		<c:if test="${not empty orgId}">
			//初始化选择框
			/* $nextAssigneeSelector = $("#nextAssignee").comboselector($.extend(employeeSelectOpts,{
				url : kl.ctx + "/fnd/employee/dataGrid?search_EQ_enable=1&search_EQ_org.id=${orgId}"
			})); */
		</c:if>

		
		$("#complete").click(function() {
			if ($("#xf-form").form("validate")) {
				var val = $("#opinion").val();
				//对于没有填写意见栏的，自动将“意见”一栏改为“同意”或“不同意”
				if (val == "") {
					if ($(":radio:checked").val() == "是") {
						$("#opinion").val("同意");
					} else {
						$("#opinion").val("不同意");
					}
				}
				//执行BeforePostUrl过程
				var beforePostUrl = "${beforePostUrl}";
				if ($(":radio:checked").val() == "否") {
					$.messager.confirm("提示", "您选择了<strong>不同意</strong>，确定要提交么？", function(r) {
						if (r) {
							if (beforePostUrl != "") {
								$.ajax({
									url : kl.ctx + beforePostUrl,
									async : false,
									type: "POST",
									data : {
										"businessId" : "${businessId}",
										"operate" : '否',
										"taskId" : '${formInfo.taskId}'
									},
									dataType : "json",
									success : function(data,textStatus){
										if(data.success){
											if(data.obj){
												if($("input[name='nextAssignee']").length==0){
													var nextAssignee="<input  name=\"nextAssignee\" value=\""+data.obj.id+"\" type=\"hidden\" >";
													$("#xf-form").append(nextAssignee);
												}else if($("input[name='nextAssignee']:enabled").length==1){
													$("input[name='nextAssignee']:enabled").val(data.obj.id);
												}else if($("input[name='nextAssignee']:disabled").length==1){
													$("input[name='nextAssignee']:disabled").prop("disabled",false).val(data.obj.id);
												}else{
													alert("无法赋值给下一审批人，请重试！");
													return false;
												}
											}
											$('#xf-form').submit();
										}else{
											showAlert(data.msg);
										}
									}
								})
							} else {
								$('#xf-form').submit();
							}
						} else {
							$("#opinion").val("");
						}
					});
				} else {
					if (beforePostUrl != "") {
						$.ajax({
							url : kl.ctx + beforePostUrl,
							async : false,
							type: "POST",
							data : {
								"businessId" : "${businessId}",
								"operate" : '是',
								"taskid" : '${formInfo.taskId}'
							},
							dataType : "json",
							success : function(data,textStatus){
								if(data.success){
									<c:choose>							  
									   <c:when test="${not empty orgId}">
											$("#nextAssigneeOrg").val(data.obj.id);
											if($("#nextAssigneeOrg").val()){
												$('#xf-form').submit();
											}else{
												alert("无法赋值给下一审批人，请重试")
											}
									   </c:when>									     
									   <c:otherwise>
									   		$('#xf-form').submit();
									   </c:otherwise>  
									</c:choose>
								}else{
									showAlert(data.msg);
								}
							}
						})
					}else{
						$('#xf-form').submit();
					}
				}
				//执行AfterPostUrl过程
				var afterPostUrl = "${afterPostUrl}";
				if (afterPostUrl != "") {
					ajaxPost(kl.ctx + afterPostUrl,function(){
						
					})
				}
			}
		});
		$(".checkboxWF").click(function(){
			var checkboxWF="";
			 $(".checkboxWF").each(function(){
				    if (true == $(this).prop("checked")) {
				    	checkboxWF+=checkboxWF==""? $(this).attr('value'):","+$(this).attr('value');
				    }
		    })
		    $("#checkboxWF").val(checkboxWF);
    	});
		
		
		remark="${remark}";
		if(remark){
			$.messager.show({
				title : "信息",
				msg : remark,
				icon : "info",
				position : "bottomRight",
				timeout:0,
				height:"auto"
			});
		}
		
		
	});
	
	function checkRadio() {
		<c:if test="${not empty assigneeUrl or not empty backAssigneeUrl}">
			var item = $(":radio:checked");
			var len = item.length;
			if (len > 0) {
				if ($(":radio:checked").val() == "否") { // 不同意的时候不要必填
					$("#nextAssignee").combobox().length>0&&$("#nextAssignee").combobox({required: false});
					$("#nextAssignee").combobox().length>0&&$("#nextAssignee").combobox('disable');
					$("#backAssignee").combobox({required: true}).combobox('enable');				
					$("#nextAssTR").fadeOut();
					$("#backAssTR").fadeIn();	
				} else {
					$("#nextAssTR").fadeIn();
					$("#backAssTR").fadeOut();	
					$("#backAssignee").combobox({required: false});
					$("#backAssignee").combobox('disable');
					$("#nextAssignee").combobox().length>0&&$("#nextAssignee").combobox({required: true}).combobox('enable');
					//$("#nextAssignee");
				}
			}
		</c:if>
	}
	 $(document).ready(function(){
		 setTimeout(function(){ checkRadio() ; },1)
	 });
	
	
</script>
</head>
<body >
<div class="easyui-panel" data-options="fit:true">
	<div class="col-sm-2"></div>
	<div class="col-sm-8">
		<form id="xf-form" method="post" action="${ctx}/bpm/confForm/form-completeTask">
		<input id="taskId" type="hidden" name="taskId" value="${formInfo.taskId}" /> <input id="businessKey" type="hidden" name="businessKey"
		value="${dynamicModel.id}" /> <input id="businessId" type="hidden" name="businessId" value="${businessId}" />
			<div>
				<table class="table table-bordered">
					<tr>
						<%-- <td></i><label class="text-success">当前任务接收人:</label></td>
						<td><span class="text-primary">${receiveMan}</span></td> --%>
						<td></i><label class="text-success">内控监督人:</label></td>
						<td><span class="text-primary">${superintendent}</span></td>
					</tr>
					<tr>
						<td></i><label class="text-success">任务申报人:</label></td>
						<td><span class="text-primary">${taskdeclare}</span></td>
					</tr>
					<tr>
						<td><label class="text-success">您正在处理的流程:</label></td>
						<td><span class="text-primary">${processName}</span></td>
					</tr>
					<tr>
						<td><label class="text-success">流程当前节点:</label></td>
						<td><span class="text-primary">${taskname}</span></td>
					</tr>
				</table>
				<table class="table table-bordered">
					<tr>
						<td colspan="2"><div align="center">
								<strong>审批意见</strong>
							</div></td>
					</tr>
					<tr>
						<td><label>是否同意:</label></td>
						<td><input type="radio" name="${nodeName}Pass" value="是" checked="checked" onclick="checkRadio()" /><label>同意</label> <input type="radio"
							name="${nodeName}Pass" value="否" onclick="checkRadio()" /><label>不同意</label></td>
					</tr>
					<c:if test="${not empty assigneeUrl }">
						<tr id="nextAssTR">
							<td><label>下一节点审批人：</label></td>
							<td><input name="nextAssignee" class="easyui-combobox" id="nextAssignee" editable="false"
								url="${ctx}/${assigneeUrl}?taskId=${formInfo.taskId}&businessId=${businessId}&orgIds=${orgIds}"> <label class="info"></label></td>
						</tr>
						
					</c:if>	
					<c:if test="${not empty backAssigneeUrl }">
						<tr id="backAssTR">
							<td><label>下一节点审批人：</label></td>
							<td><input name="nextAssignee" class="easyui-combobox" id="backAssignee" editable="false"
								url="${ctx}/${backAssigneeUrl}?taskId=${formInfo.taskId}&businessId=${businessId}&orgIds=${orgIds}"> <label class="info"></label></td>
						</tr>
						
					</c:if>	
					
					
					
					<c:if test="${not empty orgId}">
						
						<input id="nextAssigneeOrg" name="nextAssignee"  type="hidden" >
					</c:if>				
					<c:if test="${not empty checkboxWF}">
						<tr>
							<td><label>流程选择:</label></td>
							<td ><input type="hidden" name="checkboxWF" id="checkboxWF" /><input class="checkboxWF" type="checkbox" value="教务科" />教务科&nbsp;&nbsp;&nbsp;&nbsp;<input
								class="checkboxWF" type="checkbox" value="学生科" />学生科</td>
						</tr>
					</c:if>   
					<tr>
						<td><label>审批意见:</label></td>
						<td ><textarea name="${nodeName}Opinion" id="opinion"
								style="width: 550px; height: 150px; max-height: 200px; max-width: 550px" rows="3"></textarea></td>
					</tr>
					<tr>
						<td colspan="2"><div align="center">
								<input type="button" id="complete" value="提交"></input>
							</div></td>
					</tr>
				</table>
			</div>
		</form>
	</div>
	<div class="col-sm-2"></div>
	</div>
</body>
</html>